package com.gitee.wsl.struct.tree

import com.gitee.wsl.ext.NO_GETTER
import com.gitee.wsl.ext.noGetter
import com.gitee.wsl.struct.tree.builder.ChildDeclaration
import com.gitee.wsl.struct.tree.builder.LinkTreeBuilder
import com.gitee.wsl.struct.tree.builder.buildTree

open class Tree<T,E:TreeElement<T,E>>(
    override val children: List<E>,
    override val data: T = noGetter()
):NodeElement<T,E> {

    override val parent: E? get() = null

    override val elementId: Any get() = NO_GETTER

    companion object{
        fun<T> linkTree(builder: LinkTreeBuilder<T>.() -> Unit) = buildTree(builder)

        inline fun<reified T> mutableTree(root: T,
                                          childDeclaration: ChildDeclaration<T,MutableNodeElement<T>>) =
            com.gitee.wsl.struct.tree.builder.mutableTree(root,childDeclaration)
    }
}


open class MutableTree<T>(override val children: MutableList<MutableNodeElement<T>>):Tree<T,MutableNodeElement<T>>(children){
       constructor(root:MutableNodeElement<T>):this(mutableListOf(root))
}